* FigureA4.do  09/05/22
* blacks and white opioid fatality series by region

* get aggregate cross sections
use "PopSeriesAnnual.dta" if (race==`"{"Black or African American"}"' | race==`"{"White"}"') & gender=="All" & age=="0+" & year==2020, clear
replace year = 2021
tempfile fi21
save `fi21', replace
use "PopSeriesAnnual.dta" if (race==`"{"Black or African American"}"' | race==`"{"White"}"') & gender=="All" & age=="0+" & year<=2020, clear
append using `fi21'
sort gender age race state place year
save `fi21', replace

use "DeathSeriesAnnual.dta" if (race==`"{"Black or African American"}"' | race==`"{"White"}"') & gender=="All" & age=="0+" & ucd=="Drug" & mcd=="Opioid", clear
sort gender age race state place year
merge gender age race state place year using `fi21'
tab _merge
drop _merge

* analysis variables and plot
gen opioiddeathrate = deaths*100000/pop
gen byte black = race==`"{"Black or African American"}"'

gen str18 stshort="New England" if state=="Division 1: New England"
replace stshort="Middle Atlantic" if state=="Division 2: Middle Atlantic"
replace stshort="East North Central" if state=="Division 3: East North Central"
replace stshort="West North Central" if state=="Division 4: West North Central"
replace stshort="South Atlantic" if state=="Division 5: South Atlantic"
replace stshort="East South Central" if state=="Division 6: East South Central"
replace stshort="West South Central" if state=="Division 7: West South Central"
replace stshort="Mountain" if state=="Division 8: Mountain"
replace stshort="Pacific" if state=="Division 9: Pacific"

label var stshort "Census division"
#delimit ;
twoway ((line opioiddeathrate year if black==0, lcolor(gray)) (line opioiddeathrate year if black==1, lcolor(black)
  ), ylabel(,nogrid) ytitle("Deaths per 100K population") xtitle("")
  legend(order(1 "Whites" 2 "Blacks")  region(lcolor(white)))
  ), by(stshort,
  title("Figure A4a.  Opioid fatalities for blacks and whites, by Census division", size(medium))
  graphregion(color(white)) 
  note("Notes: Each data point is an aggregate of demographic groups of the same race in the same Census Division and in the same year." "Source: CDC Wonder.", size(vsmall))
  )
  name(figurea4a, replace);
#delimit cr

* national chart
collapse (sum) deaths pop, by(black year)
gen opioiddeathrate = deaths*100000/pop
#delimit ;
twoway (line opioiddeathrate year if black==0, lcolor(gray))
       (line opioiddeathrate year if black==1, lcolor(black)),
  title("Figure A4b.  Opioid fatalities for blacks and whites, US aggregates", size(medium))
  legend(order(1 "Whites" 2 "Blacks")  region(lcolor(white)))
  graphregion(color(white)) ylabel(,nogrid) ytitle("Deaths per 100K population") xtitle("")
  note("Source: CDC Wonder.", size(vsmall))
  name(figurea4b, replace);
#delimit cr




